<template>
  <!--数据字典-->
  <div class="statistics-container">
    <vab-query-form>
      <vab-query-form-left-panel :span="10">
        <el-button type="primary" icon="el-icon-plus" @click="add()">
          添加
        </el-button>
        <el-button type="primary" icon="el-icon-download" @click="handleExport">
          导出
        </el-button>
      </vab-query-form-left-panel>
      <vab-query-form-right-panel :span="14">
        <el-form :inline="true" :model="queryForm" @submit.native.prevent>
          <el-form-item>
            <el-select
              v-model="queryForm.type"
              clearable
              placeholder="请选择状态"
              @change="selectStatus()"
              style="width: 180px"
            >
              <el-option
                v-for="item in status"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button
              type="primary"
              icon="el-icon-search"
              @click="handleSearch"
            >
              查询
            </el-button>
          </el-form-item>
          <el-form-item>
            <el-button
              type="primary"
              icon="el-icon-refresh-right"
              @click="restart"
            >
              重置
            </el-button>
          </el-form-item>
        </el-form>
      </vab-query-form-right-panel>

    </vab-query-form>

    <el-table
      id="out-table"
      v-loading="listLoading"
      :data="list"
      @selection-change="setSelectRows"
    >
      <el-table-column
        align="center"
        show-overflow-tooltip
        label="序号"
        sortable
        type="index"
      />
      <el-table-column
        align="center"
        show-overflow-tooltip
        prop="title"
        label="专票类型"
      />
      <el-table-column
        align="center"
        show-overflow-tooltip
        prop="code"
        label="创建时间"
      />
      <el-table-column
        align="center"
        show-overflow-tooltip
        prop="content"
        label="操作人"
      />
      <el-table-column
        align="center"
        show-overflow-tooltip
        prop="content"
        label="描述"
      />
      <el-table-column align="center" label="操作">
        <template #default="{ row }">
          <el-button
            style="font-size: 14px; margin-right: 20px"
            type="text"
            @click="edit()"
          >
            编辑
          </el-button>
          <el-button style="font-size: 14px; margin-right: 20px" type="text">
            删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 新增编辑 -->
    <el-dialog :title="wintit" :visible.sync="dialogFormVisible" width="20%">
      <el-form :model="form" label-width="120px">
        <el-form-item>
          <el-select
            v-model="form.type"
            clearable
            placeholder="请选择状态"
            @change="selectStatus()"
            style="width: 180px"
          >
            <el-option
              v-for="item in status"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="描述:">
          <el-input v-model="form.cont" :rows="15" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="pass()">确 定</el-button>
      </div>
    </el-dialog>

    <el-pagination
      background
      :current-page="queryForm.page"
      :page-size="queryForm.list_row"
      :layout="layout"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
  </div>
</template>

<script>
//import {  } from '@/api/common'
import FileSaver from 'file-saver'
import XLSX from 'xlsx'

export default {
  name: 'Statistics',
  data() {
    return {
      queryForm: {
        title: '',
        code: '',
      },
      form: {
        com: '',
        num: '',
        cont: '',
      },
      wintit: '',
      disabled: false,
      listLoading: false,
      list: [],
      layout: 'total, sizes, prev, pager, next, jumper',
      total: 0,
      dialogFormVisible: false,
      payimg: '',
      status:[],
    }
  },
  created() {
    this.getData();
  },
  methods: {
    handleDetail() {},
    //搜索
    handleSearch() {
      this.getData()
    },
    restart() {
      this.queryForm = { }
      this.getData()
    },
    //导出
    handleExport() {
      /* 从表生成工作簿对象 */
      var wb = XLSX.utils.table_to_book(document.querySelector('#out-table'))
      /* 获取二进制字符串作为输出 */
      var wbout = XLSX.write(wb, {
        bookType: 'xlsx',
        bookSST: true,
        type: 'array',
      })
      try {
        FileSaver.saveAs(
          //Blob 对象表示一个不可变、原始数据的类文件对象。
          //Blob 表示的不一定是JavaScript原生格式的数据。
          //File 接口基于Blob，继承了 blob 的功能并将其扩展使其支持用户系统上的文件。
          //返回一个新创建的 Blob 对象，其内容由参数中给定的数组串联组成。
          new Blob([wbout], { type: 'application/octet-stream' }),
          //设置导出文件名称
          'outsheet.xlsx',
        )
      } catch (e) {
        if (typeof console !== 'undefined') console.log(e, wbout)
      }
      return wbout
    },
    getData() {
      /*let params = {
        start_time: this.queryForm.date[0],
        end_time: this.queryForm.date[1],
        type: this.queryForm.stype,
        examine_status: this.queryForm.sstatus,
        search: this.queryForm.keyword,
      }*/
      /*getSetMealOrderList(params).then((data) => {
        this.list = data.data
        this.total = data.total
      })*/
    },
    add() {
      this.dialogFormVisible = true
      this.wintit = '新增'
    },
    edit() {
      this.dialogFormVisible = true
      this.wintit = '编辑'
    },
    setSelectRows() {},
    handleSizeChange() {},
    handleCurrentChange() {},
  },
}
</script>

<style lang="scss" scoped>
.el-button {
  font-size: 14px;
  margin-right: 20px;
}
</style>
